package com.situ.web.service;

import java.util.List;

import com.situ.web.Dao.CourseDao;
import com.situ.web.entity.Course;
import com.situ.web.entity.PageInfo;


public class CourseService {
	private CourseDao courseDao = new CourseDao();

	public PageInfo findByPage(int pageNo, int pageSize) {
		PageInfo pageInfo = new PageInfo();
		pageInfo.setPageNo(pageNo);
		pageInfo.setPageSize(pageSize);
		int totalCount = courseDao.getTotalCount();
		int totalPage = (int) Math.ceil((double)totalCount/pageSize);
		pageInfo.setTotalPage(totalPage);
		int offset = (pageNo - 1) * pageSize;
		List<Course> list = courseDao.findByPage(offset,pageSize);
		pageInfo.setList(list);
		return pageInfo;
	}

	public List<Course> findAll() {
		List<Course> list = courseDao.findAll();
		return list;
	}

	public boolean deleteById(int id) {
		//dao层返回影响的行数
		int count = courseDao.deleteById(id);
		if (count == 1) {
			return true;
		} else {
			return false;
		}
	}

	public boolean insert(Course course) {
		int count = courseDao.insert(course);
		if (count == 1) {
			return true;
		} else {
			return false;
		}
	}

	public Course selectById(int id) {
		Course course = courseDao.selectById(id);
		return course;
	}

	public boolean update(Course course) {
		int count = courseDao.update(course);
		if (count == 1) {
			return true;
		} else {
			return false;
		}
	}

}
